//全局websocket ip地址端口

//var websocketDomain = 'jiepan.simaipu.net:9000';
//var websocketDomain = '180.153.43.62:9000';
var websocketDomain = 'localhost:8080';
//var websocketDomain = '106.0.4.62:8080';
var charNum = 120;

var N1001 = '<div style="font-size:xx-small;color:gray;"><strong>[</strong>\u514d\u8d23\u58f0\u660e<strong>]</strong>&nbsp;&nbsp;\u4ee5\u4e0a\u89c2\u70b9\uff08\u7b56\u7565\uff09\u4ec5\u4f9b\u53c2\u8003\uff0c\u4e0d\u6784\u6210\u5177\u4f53\u4e70\u5356\u4f9d\u636e\uff0c\u4ee5\u6295\u8d44\u8005\u81ea\u4e3b\u51b3\u7b56\u4ea4\u6613\u4e3a\u4e3b\uff0c\u636e\u6b64\u64cd\u4f5c\u98ce\u9669\u81ea\u62c5\uff01\u89e3\u76d8\u4fa0\u4fe1\u606f\u5747\u4e3a\u539f\u521b\uff0c\u4efb\u4f55\u673a\u6784\u548c\u4e2a\u4eba\u672a\u7ecf\u5141\u8bb8\u4e0d\u5f97\u8f6c\u8f7d\u3002</div>';
//var N1001 = '<div style="font-size:xx-small;color:gray;"><strong>[</strong>免责声明<strong>]</strong>&nbsp;&nbsp;以上观点（策略）仅供参考，不构成具体买卖依据，以投资者自主决策交易为主，据此操作风险自担！解盘侠信息均为原创，任何机构和个人未经允许不得转载。</div>';

// 全局 价格换算
var dataConvertContent ='';

/**
 * 判断是否达到加载条件
 * @returns {boolean}
 */
function isLoad(){
    var winH = $(window).height();
    var docH = $(document).height();
    var scrollTop = $(document).scrollTop();
    return scrollTop>=docH-winH?true:false
}

/**
 * 处理头列表选中效果
 */
function navHeaderActive(){
    var $nav = $(".nav-header>div");
    $nav.click(function () {
        $nav.removeClass("head-nav-active");
       $(this).addClass("head-nav-active");
      
    });
}
/**
 * 处理脚列表选中效果
 */
function navFooterActive(){
    var $nav = $(".nav-footer>div");
    $nav.click(function () {
        $nav.removeClass("footer-nav-active");
        $(this).addClass("footer-nav-active");
       
    });
    
  
}


function getDragger(dragUpAble,dragDownAble,wrapper){
	if(wrapper == undefined){
		wrapper = document.getElementsByName('body')[0];
	}
	var dragger = new DragLoader(wrapper, {
        dragDownThreshold:60,/*向下滑动区域*/
        dragUpThreshold:80,/*向上滑动区域*/
        dragDownRegionCls: 'DownRefresh',/*向下滑动样式*/
        dragUpRegionCls: 'UpRefresh',/*向上滑动样式*/
		disableDragDown: dragUpAble,
		disableDragUp:dragDownAble,
        /*向下滑动时的状态显示*/
        dragDownHelper: function(status) {
            if (status == 'default') {
            	var t = '<div class="load-icon-box-top">'
		                	+'<img src="images/loading.png"  style="display:none" alt=""/>'
		                    +'<span>下拉刷新数据...</span>'
		                +'</div>';
            	return t;
            } else if (status == 'prepare') {
            	var t = '<div class="load-icon-box-top">'
		                	+'<img src="images/loading.png"  style="display:inline" alt=""/>'
		                    +'<span>松开刷新数据...</span>'
		                +'</div>';
            	$(t).find('img').show(0);
		    	return t;
            } else if (status == 'load') {
            	var t = '<div class="load-icon-box-top">'
		                	+'<img src="images/loading.png"  style="display:inline" alt=""/>'
		                    +'<span>正在加载中，请稍后...</span>'
		                +'</div>';
            	$(t).find('img').show(0);
		    	return t;
            }
        },
        /*[主要code]向上滑动时的状态显示*/
        dragUpHelper: function(status) {
        	 if (status == 'default') {
             	var t = '<div class="load-icon-box-bottom" >'
 		                	+'<img src="images/loading.png"  style="display:none" alt=""/>'
 		                    +'<span>下拉刷新数据...</span>'
 		                +'</div>';
             	return t;
             } else if (status == 'prepare') {
             	var t = '<div class="load-icon-box-bottom" >'
 		                	+'<img src="images/loading.png"  style="display:inline" alt=""/>'
 		                    +'<span>松开刷新数据...</span>'
 		                +'</div>';
             	$(t).find('img').show(0);
 		    	return t;
             } else if (status == 'load') {
             	var t = '<div class="load-icon-box-bottom" >'
 		                	+'<img src="images/loading.png"  style="display:inline" alt=""/>'
 		                    +'<span>正在加载中，请稍后...</span>'
 		                +'</div>';
             	$(t).find('img').show(0);
 		    	return t;
             }
        }
    });
	return dragger;
}

/**
 * 将字串中的#。。#内容渲染成红色
 * @param msg
 */
function renderMsg(msg){
	//将内容中“#..#”部分红色显示
	 var tempContentArr = msg.split("#");
	 for(var i = 1 ; i < tempContentArr.length ; i = i+2){
		 tempContentArr[i] = '<span style="color:#E24344">#' + tempContentArr[i] + '#</span>';
	 }
	 var str = '';
	 for(var i in tempContentArr){
		 str += tempContentArr[i];
	 }
	 return str;
}

/**
 * 创建缩略文字
 */
function createClippedCharacters(content,num){
	var result = {foldFlag:false,//是否折叠标志
			wrapperClippedCharacters:'',//包裹后的缩略文字
			wrapperWholeCharacters:''//包裹后的完整文字
	};
	
	var wrapperContent = '<div>'+content+'</div>';
	
	var $htmlContent = $(wrapperContent);
	var characters = $htmlContent.text();
	
	if(characters.length > charNum ){
		result.foldFlag = true;
		var indexNum = 0;//记录当前在wrapperContent中查找字符停留的指针位置
		 var tempContent = characters.substring(0,charNum);
		 for(var i = 0 ; i < tempContent.length ; i++){
			 var char = tempContent.substr(i,1);//从i位置开始，截取一个字符
			 indexNum = wrapperContent.indexOf(char,indexNum);//查找到char位置后，修改指针停留位置
		 }
		 
		//等到循环完成，这时indexNum就是我们想要的数据，根据该数据，就可以判断可以缩略到wrapperContent的indexNum位置了
		 var clippedCharacters = wrapperContent.substring(0,indexNum);
		 clippedCharacters += '...';
		 
		//将内容中“#..#”部分红色显示
		 clippedCharacters = renderMsg(clippedCharacters);
		 result.wrapperClippedCharacters = clippedCharacters;
		
	 } 
	result.wrapperWholeCharacters = renderMsg(wrapperContent);
	return result;
}
/**
	 * 加载新数据
	 */
	function loadSlide(data,wrapper,$itemTemplate,position,clickFun){
		//console.log('main.js -> loadSlide() ----------------------');
		
	    var $wrapper = $("#"+wrapper);
	    switch (wrapper){
	        case "index-wrapper"://主页加载这里
	        	
	        	switch(position){
	            case 'top':
	            	 for(var i = 0 ; i < data.length ; i++){
	            		 var  hide = "\u5168\u6587";//var  hide = "全文";
	            		 var val = data[i];
	            		 
	            		 var tempContent = '';
	            		 var wrapperResult = createClippedCharacters(val.content,charNum);
	            		 if(wrapperResult.foldFlag){
	            			 data[i].tempContent = wrapperResult.wrapperClippedCharacters;
	            			 tempContent = wrapperResult.wrapperClippedCharacters;
	            		 } else {
	            			 hide = '';
	            			 tempContent =  wrapperResult.wrapperWholeCharacters;
	            		 }
	            		 val.content = wrapperResult.wrapperWholeCharacters;
	            		 var publishDate ="(" + val.publishDate + ")";
	            		 
	            		 //console.info('tempContent='+tempContent);
	            		 //tempContent=dataConvertContent;
	            		 dataConvert(tempContent, val.roomId, val.roomName);
//	            		 console.info('dataConvertContent='+dataConvertContent);
	            		 tempContent = dataConvertContent;
//	            		 console.info('tempContent='+tempContent);
	            		 
	            		 var $str = $itemTemplate.clone();
	            		 $str.find('.t-publishTime').text(val.publishTime);
	            		 $str.find('.t-news-content').html('['+val.roomName+']'+'<span class="news-text-content">'+tempContent+  ' </span>'+ publishDate);
	            		 $str.find('.t-news-content').append(N1001);
	            		 $str.find('.t-unfoldBtn').text(hide);
	            		 $str.find('.t-news-content img').showimg({});
	            		 
		                 $str.data('data',val);
		                 $str.click(function(){
		                	 var tempData = $(this).data('data');
		                 });
		                 $str.find('.t-unfoldBtn').click(function(){
		                	 var parent = $(this).parents('.news-box');
		                	 var curData = $(parent).data('data');
		                	 
		                	 var text = $(this).text();
		                	 if(text == '\u5168\u6587'){
		                		 $(parent).find('.news-text-content').html(curData.content+ publishDate);
		                		 $(parent).find('.news-text-content img').showimg({});
			                	 $(this).text('\u6536\u8d77');//$(this).text('收起');
		                	 } else if(text == '\u6536\u8d77'){
		                		 $(parent).find('.news-text-content').html(curData.tempContent+ publishDate);
		                		 $(parent).find('.news-text-content img').showimg({});
			                	 $(this).text('\u5168\u6587');
		                	 }
		                	 
		                 });
		                 $wrapper.prepend($str);
	            	 }
	            	break;
	            
	            default:
	            	for(var i = data.length-1; i > -1 ; i--){
	            		 var  hide = "\u5168\u6587";
	            		var val = data[i];
	            		
	            		var tempContent = '';
	            		 var wrapperResult = createClippedCharacters(val.content,charNum);
	            		 if(wrapperResult.foldFlag){
	            			 data[i].tempContent = wrapperResult.wrapperClippedCharacters;
	            			 tempContent = wrapperResult.wrapperClippedCharacters;
	            		 } else {
	            			 hide = '';
	            			 tempContent =  wrapperResult.wrapperWholeCharacters;
	            		 }
	            		 val.content = wrapperResult.wrapperWholeCharacters;
	            		 var publishDate ="(" + val.publishDate + ")";
	            		 var $str = $itemTemplate.clone();
	            		 $str.find('.t-publishTime').text(val.publishTime);
	            		 $str.find('.t-news-content').html('['+val.roomName+']'+'<span class="news-text-content">'+tempContent   + '</span>' + publishDate);
	            		 $str.find('.t-news-content').append(N1001);
	            		 $str.find('.t-unfoldBtn').text(hide);
	            		 $str.find('.t-news-content img').showimg({});
		                $str.data('data',val);
		                $str.click(function(){
		                	 var tempData = $(this).data('data');
		                 });
		                $str.find('.t-unfoldBtn').click(function(){
		                	 var parent = $(this).parents('.news-box');
		                	 var curData = $(parent).data('data');
		                	 
		                	 var text = $(this).text();
		                	 if(text == '\u5168\u6587'){
			                	 $(parent).find('.news-text-content').html(curData.content + publishDate);
			                	 $(parent).find('.news-text-content img').showimg({});
			                	 $(this).text('\u6536\u8d77');
		                	 } else if(text == '\u6536\u8d77'){
		                		 $(parent).find('.news-text-content').html(curData.tempContent + publishDate);
		                		 $(parent).find('.news-text-content img').showimg({});
			                	 $(this).text('\u5168\u6587');
		                	 }
		                	 
		                 });
		                $wrapper.append($str);
	            	}
	            	break;
	            }
	            
	            
	            break;
	        case "room-wrapper"://解盘房间加载这里
	        	//数据保持发布时间升序，当分页时，采用bottom方式添加，先加发布时间大的，后加发布时间小的
	        	//当更新数据时，采用top方式添加，先往顶部追加发布时间小的，后加发布时间大的
	        	switch(position){
		        	case 'top':
		        		for(var i = 0 ; i < data.length ; i++){
		            		 var  hide = "\u5168\u6587";
		            		 var val = data[i];
		            		 
		            		 var tempContent = '';
		            		 var wrapperResult = createClippedCharacters(val.content,charNum);
		            		 if(wrapperResult.foldFlag){
		            			 data[i].tempContent = wrapperResult.wrapperClippedCharacters;
		            			 tempContent = wrapperResult.wrapperClippedCharacters;
		            		 } else {
		            			 hide = '';
		            			 tempContent =  wrapperResult.wrapperWholeCharacters;
		            		 }
		            		 val.content = wrapperResult.wrapperWholeCharacters;
		            		 var publishDate ="(" + val.publishDate + ")";
		            		 var $str = $itemTemplate.clone();
		            		 $str.find('.t-publishTime').text(val.publishTime);
		            		 $str.find('.t-news-content').html('['+val.roomName+']'+'<span class="news-text-content">'+tempContent+'</span>'+ publishDate);
		            		 $str.find('.t-news-content').append(N1001);
		            		 $str.find('.t-unfoldBtn').text(hide);
		            		 $str.find('.t-news-content img').showimg({});
		            		 
			                 $str.data('data',val);
			                 $str.click(function(){
			                	 var tempData = $(this).data('data');
			                 });
			                 $str.find('.t-unfoldBtn').click(function(){
			                	 var parent = $(this).parents('.news-box');
			                	 var curData = $(parent).data('data');
			                	 
			                	 var text = $(this).text();
			                	 if(text == '\u5168\u6587'){
			                		 $(parent).find('.news-text-content').html(curData.content+ publishDate);
			                		 $(parent).find('.news-text-content img').showimg({});
				                	 $(this).text('\u6536\u8d77');
			                	 } else if(text == '\u6536\u8d77'){
			                		 $(parent).find('.news-text-content').html(curData.tempContent+ publishDate);
			                		 $(parent).find('.news-text-content img').showimg({});
				                	 $(this).text('\u5168\u6587');
			                	 }
			                	 
			                 });
			                 $wrapper.prepend($str);
		            	 }
		        		break;
		        	case 'bottom':
		        		for(var i = data.length-1 ; i > -1 ; i--){
		            		 var  hide = "\u5168\u6587";
			            		var val = data[i];
			            		
			            		var tempContent = '';
			            		 var wrapperResult = createClippedCharacters(val.content,charNum);
			            		 if(wrapperResult.foldFlag){
			            			 data[i].tempContent = wrapperResult.wrapperClippedCharacters;
			            			 tempContent = wrapperResult.wrapperClippedCharacters;
			            		 } else {
			            			 hide = '';
			            			 tempContent =  wrapperResult.wrapperWholeCharacters;
			            		 }
			            		 val.content = wrapperResult.wrapperWholeCharacters;
			            		 
			            		 var publishDate ="(" + val.publishDate + ")";
			            		 var $str = $itemTemplate.clone();
			            		 $str.find('.t-publishTime').text(val.publishTime);
			            		 $str.find('.t-news-content').html('['+val.roomName+']'+'<span class="news-text-content">'+tempContent+'</span>'+ publishDate);
			            		 $str.find('.t-news-content').append(N1001);
			            		 $str.find('.t-unfoldBtn').text(hide);
			            		 $str.find('.t-news-content img').showimg({});
			            		 
				                $str.data('data',val);
				                $str.click(function(){
				                	 var tempData = $(this).data('data');
				                 });
				                $str.find('.t-unfoldBtn').click(function(){
				                	 var parent = $(this).parents('.news-box');
				                	 var curData = $(parent).data('data');
				                	 
				                	 var text = $(this).text();
				                	 if(text == '\u5168\u6587'){
					                	 $(parent).find('.news-text-content').html(curData.content+ publishDate);
					                	 $(parent).find('.news-text-content img').showimg({});
					                	 $(this).text('\u6536\u8d77');
				                	 } else if(text == '\u6536\u8d77'){
				                		 $(parent).find('.news-text-content').html(curData.tempContent+ publishDate);
				                		 $(parent).find('.news-text-content img').showimg({});
					                	 $(this).text('\u5168\u6587');
				                	 }
				                	 
				                 });
				                $wrapper.append($str);
			            	}
		        		break;
		        	default:
	        			
	        	}
	        	
	            break;
	        case "precious-metal-room-wrapper"://喊单老师解盘房间加载这里
	        	//该部分与普通房间列表时间顺序相反，模拟聊天工具的排序
	        	//数据保持发布时间升序，当分页时，采用bottom方式添加，先加发布时间大的，后加发布时间小的
	        	//当更新数据时，采用top方式添加，先往顶部追加发布时间小的，后加发布时间大的
	        	//var result = {foldFlag:false,//是否折叠标志
//						wrapperClippedCharacters:'',//包裹后的缩略文字
//						wrapperWholeCharacters:''//包裹后的完整文字
//				};
	        	switch(position){
	        	case 'top':
	        		for(var i = data.length-1 ; i > -1 ; i--){
	            		 var  hide = "\u5168\u6587";
	            		 var val = data[i];
	            		 var tempContent = '';
	            		 var wrapperResult = createClippedCharacters(val.content,charNum);
	            		 if(wrapperResult.foldFlag){
	            			 data[i].tempContent = wrapperResult.wrapperClippedCharacters;
	            			 tempContent = wrapperResult.wrapperClippedCharacters;
	            		 } else {
	            			 hide = '';
	            			 tempContent =  wrapperResult.wrapperWholeCharacters;
	            		 }
	            		 val.content = wrapperResult.wrapperWholeCharacters;
	            		 var publishDate ="(" + val.publishDate + ")";
	            		 
	            		 var $str = $itemTemplate.clone();
	            		 $str.find('.t-publishTime').text(val.publishTime);
	            		 
	            		 var $delBtn = $('<span style="color:blue;" >删除</span>');
	            		 $delBtn.click(function(){
	            			 if(confirm("确定要删除数据吗")){
		            			 var parent = $(this).parents('.news-box').get(0);
		            			 var $parent = $(parent);
		            			 var itemData = $parent.data('data');
		            			 $.ajax({
		            				 url:'../room/delMsg.do',
		            				 data:{msgId:itemData.id},
		            				 type:'post',
		            				 dataType:'json',
		            				 success:function(d){
		            					 if(d.success){
		            						 
		            					 }
		            				 }
		            			 });
	            			 }
	            		 });
	            		 $str.attr('name',val.id);
	            		 
	            		 $str.find('.t-news-content').html('['+val.roomName+']'+'<span class="news-text-content">'+tempContent+'</span>'+ publishDate);
	            		 $str.find('.t-news-content').append(N1001);
	            		 $str.find('.t-news-content').append($delBtn);
	            		 
	            		 $str.find('.t-unfoldBtn').text(hide);
	            		 $str.find('.t-news-content img').showimg({});
		                 $str.data('data',val);
		                 $str.click(function(){
		                	 var tempData = $(this).data('data');
		                 });
		                 $str.find('.t-unfoldBtn').click(function(){
		                	 var parent = $(this).parents('.news-box');
		                	 var curData = $(parent).data('data');
		                	 
		                	 var text = $(this).text();
		                	 if(text == '\u5168\u6587'){
		                		 $(parent).find('.news-text-content').html(curData.content+ publishDate);
		                		 $(parent).find('.news-text-content img').showimg({});
			                	 $(this).text('\u6536\u8d77');
		                	 } else if(text == '\u6536\u8d77'){
		                		 $(parent).find('.news-text-content').html(curData.tempContent+ publishDate);
		                		 $(parent).find('.news-text-content img').showimg({});
			                	 $(this).text('\u5168\u6587');
		                	 }
		                	 
		                 });
		                 
		                 
		                 $wrapper.prepend($str);
	            	 }
	        		break;
	        	case 'bottom'://适合初始化加载第一个页数据
	        		for(var i = 0 ; i < data.length ; i++){
	            		 var  hide = "\u5168\u6587";
		            		var val = data[i];
		            		 var tempContent = '';
		            		 var wrapperResult = createClippedCharacters(val.content,charNum);
		            		 if(wrapperResult.foldFlag){
		            			 data[i].tempContent = wrapperResult.wrapperClippedCharacters;
		            			 tempContent = wrapperResult.wrapperClippedCharacters;
		            		 } else {
		            			 hide = '';
		            			 tempContent =  wrapperResult.wrapperWholeCharacters;
		            		 }
		            		 val.content = wrapperResult.wrapperWholeCharacters;
		            		 var publishDate ="(" + val.publishDate + ")";
		            		 
		            		 var $str = $itemTemplate.clone();
		            		 $str.find('.t-publishTime').text(val.publishTime);
		            		 
		            		 var $delBtn = $('<span style="color:blue;" >删除</span>');
		            		 $delBtn.click(function(){
		            			 if(confirm("确定要删除数据吗")){
			            			 var parent = $(this).parents('.news-box').get(0);
			            			 var $parent = $(parent);
			            			 var itemData = $parent.data('data');
			            			 $.ajax({
			            				 url:'../room/delMsg.do',
			            				 data:{msgId:itemData.id},
			            				 type:'post',
			            				 dataType:'json',
			            				 success:function(d){
			            					 if(d.success){
			            						 
			            					 }
			            				 }
			            			 });
		            			 }
		            		 });
		            		 $str.attr('name',val.id);
		            		 
		            		 $str.find('.t-news-content').html('['+val.roomName+']'+'<span class="news-text-content">'+tempContent+ '</span>'+ publishDate);
		            		 $str.find('.t-news-content').append(N1001);
		            		 $str.find('.t-news-content').append($delBtn);
		            		 
		            		 $str.find('.t-unfoldBtn').text(hide);
		            		 $str.find('.t-news-content img').showimg({});
		            		 
			                $str.data('data',val);
			                $str.click(function(){
			                	 var tempData = $(this).data('data');
			                 });
			                $str.find('.t-unfoldBtn').click(function(){
			                	 var parent = $(this).parents('.news-box');
			                	 var curData = $(parent).data('data');
			                	 
			                	 var text = $(this).text();
			                	 if(text == '\u5168\u6587'){
			                		 
				                	 $(parent).find('.news-text-content').html(curData.content+ publishDate);
				                	 $(parent).find('.news-text-content img').showimg({});
				                	 $(this).text('\u6536\u8d77');
			                	 } else if(text == '\u6536\u8d77'){
			                		 $(parent).find('.news-text-content').html(curData.tempContent+ publishDate);
			                		 $(parent).find('.news-text-content img').showimg({});
				                	 $(this).text('\u5168\u6587');
			                	 }
			                	 
			                 });
			                $wrapper.append($str);
		            	}
	        		break;
	        	default:
	        		
	        	}
	        	
	        	break;
	    }
	}
	
	/**
	 * 差异提取新数据集中在界面不存在的数据
	 */
	function getNewData(newDataList,oldDataArr){
		var newDataArr = [];
		if(oldDataArr.length != newDataList.length){
			var index = oldDataArr.length;
			for(var i = index ; i < newDataList.length ; i++){
				newDataArr.push(newDataList[i]);
			}
		}
		return newDataArr;
		
	}
	

	/**用户信息*/
	function initUserInfo(callback){
		$.ajax({
			url:'../member/permissions.do',
			type:'get',
			dataType:'json',
			success:function(d){
				if(d.success){
				} 
				callback(d);
			}
		});
	}
	
	/**
	 * 获取本地存储的用户信息
	 * userInfo = {code:code,pwd:pwd,nick:d.data.nick,mphone:d.data.mphone,email:d.data.email,permissions:[],roles:[],_loginStatus:false,_loginStatus:true};
	 * @returns
	 */
	function getLocalUserInfo(){
		if(window.localStorage){
			var userInfoStr = window.localStorage.getItem('userInfo');
			if(userInfoStr){
				var userInfo = JSON.parse(userInfoStr);
				return userInfo
			}
		} 
		return null;
	}
	/**
	 * 获取本地存储的 临时用户信息
	 * userInfoTmp = {id:d.data.id,trade:d.data.tradeName,tmpulist:d.data.tmpulist,_loginStatus:true,_loginStatus:true};
	 * @returns
	 */
	function getLocalUserInfoTmp(){
		if(window.localStorage){
			var userInfoStr = window.localStorage.getItem('userInfoTmp');
			if(userInfoStr){
				var userInfoTmp = JSON.parse(userInfoStr);
//				console.log('main.js -> getLocalUserInfoTmp = '+ JSON.stringify(userInfoTmp));
				return userInfoTmp
			}
		} 
		return null;
	}
	
	
	/**
	 * 角色校验
	 */
	function hasRole(role,roles){
		if(roles == null || roles.length == 0){
			return false;
		}
		for(var i in roles){
			if(roles[i] == role){
				return true;
			}
		}
		return false;
	}
	
	/**
	 * 
	 */
	function hasPermission(permission,permissions){
		if(permissions ==  null || permissions.length == 0){
			return false;
		}
		var targetPerArr = permission.split(':');
		//补星
		if(targetPerArr.length == 1){
			targetPerArr.push('*');
			targetPerArr.push('*');
		} else if(targetPerArr.length == 2){
			targetPerArr.push('*');
		}
		//循环对比验证，如果占位符是*，表示通配
		for(var i in permissions){
			var perArr = permissions[i].split(':');
			//补星
			if(perArr.length == 1){
				perArr.push('*');
				perArr.push('*');
			} else if(perArr.length == 2){
				perArr.push('*');
			}
			
			var flag1 = true;
			var flag2 = true;
			var flag3 = true;
			
			if(perArr[0] != '*'){
				flag1 = perArr[j] == targetPerArr[0] ? true:false;
			}
			if(perArr[1] != '*'){
				flag1 = perArr[j] == targetPerArr[0] ? true:false;
			}
			if(perArr[3] != '*'){
				flag1 = perArr[j] == targetPerArr[0] ? true:false;
			}
			
			if(flag1 && flag2 && flag3){
				return true;
			}
		}
		return false;
	}
	
	/**
	 * 设置页面滚动条到窗口底部，以便显示最新消息
	 */
	function setScrollBar2Bottom(){
		var winH = $(window).height();
	    var docH = $(document).height();
	    var difH = docH-winH;
	    $('body').scrollTop(difH-10);
	}
	
	 function heartFun(isAsyn,callback){
		 
	    	$.ajax({
	    		url:'../sys/heart.do',
	    		type:'get',
	    		async:isAsyn,
	    		dataType:'json',
	    		success:function(d){
	    			if(d.success){
//	    				console.log('main.js --> d.data = '+d.data);
	    				
	    				if(window.localStorage){
	    					var oldUserInfo = getLocalUserInfo();
	    					if(oldUserInfo){
	    						var defaultUserInfo = {nick:d.data.nick,mphone:d.data.mphone,email:d.data.email,trade:d.data.tradeName,permissions:[],roles:[],ulist:d.data.ulist,_loginStatus:true,_loginStatus:true};
//	    						var defaultUserInfo = {nick:d.data.nick,mphone:d.data.mphone,email:d.data.email,permissions:[],roles:[],ulist:d.data.ulist,_loginStatus:true,_loginStatus:true};
	    						var userInfo = $.fn.extend({},oldUserInfo, defaultUserInfo);
	    						initUserInfo(function(data){
	    							userInfo.permissions = data.data.permissions;
	    							userInfo.roles = data.data.roles;
	    							var userInfoStr = JSON.stringify(userInfo); 
	    							window.localStorage.setItem('userInfo',userInfoStr);
	    							if(typeof callback == 'function'){
	    								callback();
	    							}
	    						});
	    						
	    					} else {
	    						var userInfo = {nick:d.data.nick,mphone:d.data.mphone,email:d.data.email,trade:d.data.tradeName,permissions:[],roles:[],ulist:d.data.ulist,_loginStatus:true,_loginStatus:true};
//	    						var userInfo = {nick:d.data.nick,mphone:d.data.mphone,email:d.data.email,permissions:[],roles:[],ulist:d.data.ulist,_loginStatus:true,_loginStatus:true};
	    						initUserInfo(function(data){
	    							userInfo.permissions = data.data.permissions;
	    							userInfo.roles = data.data.roles;
	    							var userInfoStr = JSON.stringify(userInfo); 
	    							window.localStorage.setItem('userInfo',userInfoStr);
	    							if(typeof callback == 'function'){
	    								callback();
	    							}
	    						});
	    						
	    					}
							
						}
	    			} else {
	    				//如果服务器离线，这里自动登录
	    				var userInfo = getLocalUserInfo();
	    				if(userInfo){
	    					var code = userInfo.code;
	    					var pwd = userInfo.pwd;
	    					$.ajax({
	    	    				url:'../authen/login.do',
	    	    				type:'post',
	    	    				data:{code:code,pwd:pwd},
	    	    				dataType:'json',
	    	    				success:function(d){
	    	    					if(d.success){
	    	    						if(window.localStorage){
	    	    							var userInfo = {code:code,pwd:pwd,nick:d.data.nick,mphone:d.data.mphone,email:d.data.email,trade:d.data.tradeName,permissions:[],roles:[],ulist:d.data.ulist,_loginStatus:true,_loginStatus:true};
//	    	    							var userInfo = {code:code,pwd:pwd,nick:d.data.nick,mphone:d.data.mphone,email:d.data.email,permissions:[],roles:[],ulist:d.data.ulist,_loginStatus:true,_loginStatus:true};
	    	    							initUserInfo(function(data){
	    	    								userInfo.permissions = data.data.permissions;
	    	    								userInfo.roles = data.data.roles;
	    	    								var userInfoStr = JSON.stringify(userInfo); 
	    	    								window.localStorage.setItem('userInfo',userInfoStr);
	    	    								if(typeof callback == 'function'){
	    		    								callback();
	    		    							}
	    	    							});
	    	    							
	    	    						}
	    	    						
	    	    					} else {
	    	    						userInfo._loginStatus = false;
	    	    						var userInfoStr = JSON.stringify(userInfo); 
	    	    						window.localStorage.setItem('userInfo',userInfoStr);
	    	    						if(typeof callback == 'function'){
		    								callback();
		    							}
	    	    					}
	    	    				}
	    	    			});
	    				}
	    				
						
	    			}
	    			if(isAsyn){//只有异步情况才开启定时心跳
	    				setTimeout(function(){
	    			    	 heartFun(true);
	    				},12000000);//20分钟一次，实际可以和服务器session过期时间保持一致
	    			}
	    		},
	    		error:function(XMLHttpRequest){//遇到错误后，停止心跳
	    			if(window.localStorage){
						var userInfo = getLocalUserInfo();
						userInfo._loginStatus = false;
						var userInfoStr = JSON.stringify(userInfo); 
						window.localStorage.setItem('userInfo',userInfoStr);
					}
	    		}
	    	});
	    };
	 
    
	    
	    // 临时用户心跳 存储临时用户缓存 到localStorage
	    function heartFunTmp(isAsyn,callback){
	    	var userId;
	    	var userInfoTmp = getLocalUserInfoTmp();
	    	if(userInfoTmp){	    		
	    		userId = userInfoTmp.id;
	    	}
	    	$.ajax({
//	    		url:'../sys/heartTmpUser.do',
	    		url:'../sys/loginTmp.do',
	    		type:'get',
	    		data:{userId:userId},
	    		async:isAsyn,
	    		dataType:'json',
	    		success:function(d){
	    			if(d.success){
	    				if(window.localStorage){
	    					var oldUserInfo = getLocalUserInfoTmp();
	    					if(oldUserInfo){
	    						var defaultUserInfo = {id:d.data.id,trade:d.data.tradeName,tmpulist:d.data.tmpulist,_loginStatus:true,_loginStatus:true};
	    						var userInfo = $.fn.extend({},oldUserInfo, defaultUserInfo);
	    						var userInfoStr = JSON.stringify(userInfo); 
//	    						console.log('#### 1 main.js -> userInfoStr = '+ userInfoStr);
    							window.localStorage.setItem('userInfoTmp',userInfoStr);
	    					} else {
	    						var userInfo = {id:d.data.id,trade:d.data.tradeName,tmpulist:d.data.tmpulist,_loginStatus:true,_loginStatus:true};
	    						var userInfoStr = JSON.stringify(userInfo);
//	    						console.log('#### 2 main.js -> userInfoStr = '+ userInfoStr);
    							window.localStorage.setItem('userInfoTmp',userInfoStr);
	    					}
							
						}
	    			}else{
	    				//如果服务器离线，这里自动登录
	    				var userInfoTmp = getLocalUserInfoTmp();
	    				if(userInfoTmp){
	    					var userId = userInfoTmp.id;
	    					$.ajax({
	    	    				url:'../sys/loginTmp.do',
	    	    				type:'post',
	    	    				data:{userId:userId},
	    	    				dataType:'json',
	    	    				success:function(d){
	    	    					if(d.success){
	    	    						if(window.localStorage){
	    	    							var userInfoTmp = {id:d.data.id,trade:d.data.tradeName,tmpulist:d.data.tmpulist,_loginStatus:true,_loginStatus:true};
	    	    							var userInfoStr = JSON.stringify(userInfoTmp); 
//	    	    							console.log('#### 3 main.js -> userInfoStr = '+ userInfoStr);
    	    								window.localStorage.setItem('userInfoTmp',userInfoStr);
	    	    						}
	    	    					} else {
	    	    						userInfo._loginStatus = false;
	    	    						var userInfoStr = JSON.stringify(userInfoTmp);
//	    	    						console.log('#### 4 main.js -> userInfoStr = '+ userInfoStr);
	    	    						window.localStorage.setItem('userInfo',userInfoStr);
	    	    						if(typeof callback == 'function'){
		    								callback();
		    							}
	    	    					}
	    	    				}
	    	    			});
	    				}
	    			}
	    			if(isAsyn){//只有异步情况才开启定时心跳
	    				setTimeout(function(){
	    					heartFunTmp(true);
	    				},12000000);//20分钟一次，实际可以和服务器session过期时间保持一致
	    			}
	    		},
	    		error:function(XMLHttpRequest){//遇到错误后，停止心跳
	    			if(window.localStorage){
						var userInfo = getLocalUserInfoTmp();
//						userInfo._loginStatus = false;
						var userInfoStr = JSON.stringify(userInfo);
//						console.log('#### 5 main.js -> userInfoStr = '+ userInfoStr);
						window.localStorage.setItem('userInfoTmp',userInfoStr);
					}
	    		}
	    	});
	    };
   
	    
/**jquery自动化执行代码*/
$(function () {
    /**拖动插件结束*/
    navHeaderActive();
    navFooterActive();
    //处理css/js文件缓存
    $(document).ready(function(){
        var t = new Date();
        $('#css').attr('href', "stylesheets/main.css?t="+t.getTime());
        $('#js').attr('src', "javascripts/main.js?t="+t.getTime());
    });
    
    //服务器session 通过心跳保持登录状态，心跳时间间隔是20分钟
    heartFunTmp(true);
    heartFun(true);
});


/**
 * 判断是否达到加载条件
 * @returns {boolean}
 */
function isLoad(){
    var winH = $(window).height();
    var docH = $(document).height();
    var scrollTop = $(document).scrollTop();
    return scrollTop>=docH-winH?true:false
}

/**
 * 判断是否达到加载条件
 * @returns {boolean}
 */
function dataConvert(tempContent, roomId, roomName){
	$.ajax({
		async:false,
        type : "get",
        dataType : "json",
        url : "../hall/dataConvert.do", // 你请求的地址
        data : {
        	content:tempContent,
        	msgRoomId:roomId,
        	roomName:roomName
        },
        success : function(data){
        	dataConvertContent=data.data;
        	//console.log('main.js -> dataConvert -> data : '+dataConvertContent);
        }
    });
	
}


